/**
 * Created by Administrator on 2017/3/21.
 */
import React, {Component} from 'react';
import { Form, Input, Radio, Select, Switch, Button, Tooltip, Icon } from 'antd';
import request from '@/utils/request';
import { connect } from 'dva';
import styles from '../../layouts/password.less';
const FormItem = Form.Item;
const { TextArea } = Input;

const RadioGroup = Radio.Group;
const Option = Select.Option;
class AddPoliciesForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      all_roles:[],
      level:0,
    };
  }
  componentDidMount() {
    const that=this;
    request(`/all_roles`, {
      method: 'GET',
    }).then((response)=> {
      console.log('all_permissions', response)
      if(response.status===200){
        that.setState({
          all_roles:response.data.data
        })
      }
    })
  }
  changePassword=(e)=> {
    let value=e.target.value
    let level = 0;
    //正则表达式验证符合要求的
    if(/\d/.test(value)) level++; //数字
    if(/[A-Z]/.test(value)) level++; //小写
    if(/[a-z]/.test(value)) level++; //特殊字符
    if(value.length < 8||value.length > 16)  level=0;
    //逻辑处理
    this.setState({
      level:level
    })
  }
  render() {
    const formItemLayoutWithLabel = {
      labelCol: {
        xs: {span: 24},
        sm: {span: 7},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 15},
      }
    };

    const {getFieldDecorator} = this.props.form;
    return (
      <div>
        <Form onSubmit={this.handleSubmit}>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
                网点名称
            </span>
            )}
          >
            {getFieldDecorator('name', {
              initialValue: this.props.editRecord ? this.props.editRecord.name : '',
              rules: [{ required: true, message: '请输入名称' }],
            })(
              <Input/>
            )}
          </FormItem>

          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
                网点地址
            </span>
            )}
          >
            {getFieldDecorator('address', {
              initialValue: this.props.editRecord ? this.props.editRecord.address : '',
            })(
              <Input/>
            )}
          </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
                网点电话
            </span>
            )}
          >
            {getFieldDecorator('telephone', {
              initialValue: this.props.editRecord ? this.props.editRecord.telephone : '',
            })(
              <Input/>
            )}
          </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
                备注
            </span>
            )}
          >
            {getFieldDecorator('remark', {
              initialValue: this.props.editRecord ? this.props.editRecord.remark : '',
            })(
              <Input/>
            )}
          </FormItem>
        </Form>
      </div>
    );
  }
}

const AddPoliciesFormWrap = Form.create()(AddPoliciesForm);
export default connect()(AddPoliciesFormWrap);


